import request from '@/utils/request'

// 查询商品列表
export function listProducts(query) {
  return request({
    url: '/api/v1/products/list',
    method: 'get',
    params: query
  })
}

// 获取商品详情
export function getProduct(id) {
  return request({
    url: `/api/v1/products/form/${id}`,
    method: 'get'
  })
}

// 新增商品
export function addProduct(data) {
  return request({
    url: '/api/v1/products/save',
    method: 'post',
    data: data
  })
}

// 修改商品
export function updateProduct(data) {
  return request({
    url: '/api/v1/products/update',
    method: 'post',
    data: data
  })
}

// 删除商品
export function delProduct(ids) {
  return request({
    url: `/api/v1/products/delete/${ids}`,
    method: 'delete',
    params: {
      ids: ids
    }
  })
}

// 上传商品Excel
export function uploadProducts(file) {
  const formData = new FormData()
  formData.append('file', file)
  
  return request({
    url: '/api/v1/products/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 获取首页统计数据
export function getProductsStats() {
  return request({
    url: '/api/v1/products/jump/all',
    method: 'get'
  })
}

// 获取商品浏览和直达链接统计
export function getProductsJumpStats() {
  return request({
    url: '/api/v1/products/jump/all',
    method: 'get'
  })
}
